package com.microlearning.common.rabbitmq.publisher;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Topic(通配符订阅)交换机：与Direct相似，路由key可以使用通配符
 * 特点：
 *      1、
 */
@Service
public class TopicPublisher {

    RabbitTemplate rabbitTemplate;

    @Autowired
    public TopicPublisher(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    /**
     * 交换机名称
     */
    static String exchangeName = "mic.topic";

    /**
     * 消息内容
     */
    static String message = "mic.helloDirect";

    /**
     * 发送消息到交换机
     */
    public void pushMessage(String exchangeName, String routing, String message) {
        rabbitTemplate.convertAndSend(exchangeName, routing, message);
    }

}
